package org.example.actualcombat.demos.web.modules.pms.controller;


import cn.hutool.core.thread.ThreadException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import org.example.actualcombat.demos.web.common.api.CommonPage;
import org.example.actualcombat.demos.web.common.api.CommonResult;
import org.example.actualcombat.demos.web.modules.pms.model.dto.PmsProductSaveParamDTO;
import org.example.actualcombat.demos.web.modules.pms.model.PmsProduct;
import org.example.actualcombat.demos.web.modules.pms.model.dto.PmsProductUpdateInitDTO;
import org.example.actualcombat.demos.web.modules.pms.model.dto.ProductConditionDTO;
import org.example.actualcombat.demos.web.modules.pms.service.PmsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
@Api(tags="对类的修饰,商品控制")

public class PmsProductController {
    @Autowired
    PmsProductService productService;
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value = "获取列表,api",notes = "获取列表,notes部分")
    @ApiResponses(value={
            @ApiResponse(code=200,message = "成功获取用户信息1"),
            @ApiResponse(code = 404,message = "未找到用户")
    })
    public CommonResult list(@ApiParam(value = "用户对象1",required = true,example = "{}") ProductConditionDTO productConditionDTO){
        // 多参数,声明一个dto对象统一接受. 不然写起来显示乱
        /*
        *   //   keyword: null,
          //   pageNum: 1,
          //   pageSize: 5,
          //   publishStatus: null,
          //   verifyStatus: null,
          //   productSn: null,
          //   productCategoryId: null,
          //   brandId: null
        * */
        Page page =  productService.getList(productConditionDTO);
        return  CommonResult.success(CommonPage.restPage(page));
    }
    @RequestMapping(value = "/update/deleteStatus",method = RequestMethod.POST)
    public CommonResult deleteStatus(@RequestParam(value = "ids") List<Long> ids){
       Boolean b =   productService.updateStatus(ids);
               return CommonResult.success(b);
    }

    @Transactional
    @RequestMapping(value = "/update/newStatus",method = RequestMethod.POST)
    public CommonResult updateNewStatus(@RequestParam("newStatus" )Integer newStatus,@RequestParam("ids") List<Long> ids){
        Boolean b =  productService.updateStatus1(newStatus,ids, PmsProduct::getNewStatus);
        return CommonResult.success(b);
    }
    @Transactional
    @RequestMapping(value = "/update/recommendStatus",method = RequestMethod.POST)
    public CommonResult updateRecommendStatus(@RequestParam("recommendStatus" )Integer recommendStatus,@RequestParam("ids") List<Long> ids){
        Boolean b =  productService.updateStatus1(recommendStatus,ids, PmsProduct::getRecommandStatus);
        return CommonResult.success(b);
    }
    @Transactional
    @RequestMapping(value = "/update/publishStatus",method = RequestMethod.POST)
    public CommonResult updatePublishStatus(@RequestParam("publishStatus" )Integer publishStatus,@RequestParam("ids") List<Long> ids){
        Boolean b =  productService.updateStatus1(publishStatus,ids, PmsProduct::getPublishStatus);
        return CommonResult.success(b);
    }


    @RequestMapping(value = "/create",method = RequestMethod.POST)
    @Transactional
    @ApiOperation(value = "创建")
    public CommonResult createProduct(@RequestBody PmsProductSaveParamDTO product){
        try {
            System.out.println("product = " + product);
            Boolean b=  productService.createProduct(product);
            return  CommonResult.success(b);
        }catch (Exception e){
            throw new ThreadException(e);
        }

    }


    @RequestMapping(value = "/updateInfo/{id}",method = RequestMethod.GET)
    public CommonResult getProductInfo(@PathVariable(value = "id") Long id){
        PmsProductUpdateInitDTO updateInitDTO =  productService.getInfo(id);
        return CommonResult.success(updateInitDTO);
    }








    





















}













